﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AzureProvider.ssdsClient;
using System.Collections.Specialized;

namespace AzureProvider.SoupMethods
{
    public class StopWordsMethods : BaseMethods 
    {
        protected override string containerId
        {
            get { return "StopWords"; }
        }

        protected override string kind
        {
            get { return "StopWord"; }
        }

        protected override Entity CreateEntity(object Object)
        {
            string myobj = (string)Object;

            var entity = new Entity()
            {
                Id = Guid.NewGuid().ToString(),
                Kind = kind
            };

            entity.Properties = new Dictionary<string, object>();
            entity.Properties.Add("StopWord", myobj);

            return entity;
        }

        public override object CreateObject(Entity Entity)
        {
            string myObj = (string)Entity.Properties.Single(tt => tt.Key == "StopWord").Value; 

            return myObj;
        }


        public StringCollection LoadStopWords(out string errMessage)
        {
            StringCollection dic = new StringCollection();

            foreach (string set in
                    GetObjects(null, out errMessage).Cast<string>())
            {
                dic.Add(set );
            }

            return dic;
        }

        public void InsertStopWords(StringCollection stopwords, out string errMessage)
        {
            errMessage = null;
            foreach (string str in stopwords)
            {
                Insert(str, out errMessage);
            }
        }
    }
}
